#!/bin/sh

KERNELVER=$(python -c "import sys
sys.path.insert(0, './spec')
import mi_config; print mi_config.mikernelver")
SRCDIR=`pwd`
DESTDIR=`cd $SRCDIR/..; pwd`/MagicInstaller.exp
POSTFIX="$1"
[ -n "$POSTFIX" ] && POSTFIX="-$POSTFIX"

EXPORTLST=(bindir/boot_fdr.zip
bindir/mb-vmlinuz-$KERNELVER
bindir/kmodules-$KERNELVER.tar.bz2
bindir/grub4dos-0.4.5b-2010-05-31.zip
bindir/splash.xpm.gz
bindir/root.step1.tar.gz
bindir/mbroot.src.tar.gz
bindir/root.src.tar.gz)

echo "$SRCDIR -> $DESTDIR"

if [ -e $DESTDIR ] ; then
    rm -rf $DESTDIR
fi
mkdir $DESTDIR
mkdir $DESTDIR/bindir
mkdir $DESTDIR/tmp

# Copy source file
cd $SRCDIR
git-ls-files | cpio -p --make-directories $DESTDIR

# Copy bin file

# Copy bin file
for binfile in "${EXPORTLST[@]}" ; do
    install $binfile $DESTDIR/$binfile
done

# Do a dist tag
touch $DESTDIR/.distmode

# Tar it
cd $DESTDIR/..
tar -cf ${DESTDIR}${POSTFIX}.tar MagicInstaller.exp
md5sum ${DESTDIR}${POSTFIX}.tar > ${DESTDIR}${POSTFIX}.tar.md5sum
